<?php

namespace App\Jobs;

use App\Events\UserLoanRequestQueryResultEvent;
use App\Facades\SamLogFacade;
use App\Models\UserLoanRequest;
use Illuminate\Bus\Queueable;
use Illuminate\Queue\SerializesModels;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;
use Illuminate\Support\Facades\Log;

class QueryLoanRequestResultPushJob implements ShouldQueue
{
    use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;

    /**
     * Create a new job instance.
     *
     * @return void
     */
    public function __construct()
    {

    }

    /**
     * Execute the job.
     *
     * @return void
     */
    public function handle()
    {
        $requests = UserLoanRequest::where('status',UserLoanRequest::STATUS_APPLY)
            ->where('retry','<>',UserLoanRequest::RETRY_YES)
            ->get();
        $requests->map(function($item){
            SamLogFacade::debug("授信记录【{$item->id}】进入查询结果事件");
            if($item->credit_id){
                event(new UserLoanRequestQueryResultEvent($item->credit_id));
            }
        });
    }
}
